﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using DynSim;
using DynSim.EntityFramework;
using DynSim.Basics;
using DynSim.Entities;
using System.Timers;

namespace DynSim.Basics
{
    public class FPSCalculator : GameComponent
    {
        public float frameRate;
        float frameCount;

        Timer timer;

        public FPSCalculator(Game game)
            : base(game)
        {
            game.Components.Add(this);
            game.IsFixedTimeStep = false;

            timer = new Timer();
            timer.Interval = 1000;
            timer.Elapsed += timer_Elapsed;
            timer.Start();
        }

        public override void Update(GameTime gameTime)
        {
            ++frameCount;

            base.Update(gameTime);
        }

        public void timer_Elapsed(object sender, ElapsedEventArgs args)
        {
            frameRate = frameCount;
            frameCount = 0;
        }
    }
}
